package com.johnny.xia.base;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

import com.johnny.xia.util.http.HttpClientCommand;

public class Mytest extends Thread{
	
	static AtomicLong along = new AtomicLong();
	
	static long	blong =0;
	

	public static HttpClientCommand command = new HttpClientCommand();
	static{
		command.setUrl("http://10.8.4.81:8001/m/validEmailActiveUrl?registerComfirm=QnovcGpRelFERjlOVmZCcHNzTTMvM2ZEM3dyWUs5S2lMTmgvTGt2TW5kQWgyZ1BkN1N4T3FMZUNkN0xGWjRrV1NzTUxMNCszdEJUWHVoNHp2eXh0UlBVbzJydHVxdTV2MUsvZ0E1aVBPR1Nkb056ZG9wUXB4MTV6U0QvdWdBa21zN1hlNldiU0lxdldWRldNRSswN1QxZ0JVeGtGWVRib3U3blZrMzdoMUdacTNybHJSTWc4a2dJR1drUHNxb2l5");
		command.setType("GET");
	}
	
	   public static double MAXMIN(double score , int min , int max){
	        return Math.max(Math.min(score, max),min);
	    }
	
	
	public static void main(String[] args) throws ParseException {
	    
	    for(int i=1;i<=4;i++){
	        short j = (short)i;
	        System.out.println(j);
	    }
	    
	    String[] pays = "10,50,100,200,500,1000".split(",");
	    String[] rates = "0.03,0.03,0.03,0.03,0.03,0.03".split(",");
	    int[] payAmountStep = new int[pays.length];
	    float[] payStepRate = new float[pays.length];
	    
	    for(int i=0;i<pays.length;i++){
	        payAmountStep[i] = Integer.parseInt(pays[i]);
	        payStepRate[i] = Float.parseFloat(rates[i]);
	    }
	   
	   int[] testPay = new int[]{1,5,10,50,100,200,500,1000,2000};
	   for(int payAmount : testPay){
	       int _payAmount = payAmount;
	       float subRate = 0;
	        
	        if(payAmount <= payAmountStep[0]){
	            subRate = payStepRate[0]/payAmountStep[0]*payAmount;
	        }else if(payAmount >= payAmountStep[payAmountStep.length-1]){
	            float all = 0;
	            for(int i=0;i<pays.length;i++){
	                all += payStepRate[i];
	            }
	            
	            subRate = all;
	        }else{
	            for(int i=0;i<payAmountStep.length;i++){
	               if(i == 0){
	                   subRate = payStepRate[0];
	                   payAmount -= payAmountStep[0];
	               }else{
	                   if(payAmount > (payAmountStep[i] - payAmountStep[i-1])){
	                       subRate += payStepRate[i];
	                       payAmount -= payAmountStep[i] - payAmountStep[i-1];
	                   }else{
	                       subRate += (payStepRate[i]/(payAmountStep[i] - payAmountStep[i-1]))*payAmount;
	                       break;
	                   }
	               }
	            }
	        }
	        
	        System.out.println("充值金额："+_payAmount+",抵扣："+subRate);
	   }
	   
	    
	    
	    
	    
	    
	    
	    
//	    int i = 0;
//	    int j=1;
//	    float r = 0.9F;
//	    
//	    i += j*1*r;
//	    
//	    System.out.println(i);
//	    
	    
//	    
//	     float protectRate=30;
//	    
//	     float protectCannonRate=20;
//	    
//	     float protectVipRate = 5;
//	     
//	     for(int vip=0;vip<=9;vip++){
//	         float sysScore = 1000 * (100/protectCannonRate+protectRate)*(1+vip/protectVipRate);
//	         System.out.println(sysScore);
//	         
//	     }
	    
	    

	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    
	    

      /*  int[] sendScoreScope = new int[] { 1125000, 3375000 };
        int SendRate = 8;

        int sendScore = 3375000;
        int score = 100000;

        while (sendScore >= 0){
            double rate = MAXMIN(Math.pow(sendScore * 1.0 / sendScoreScope[1],1), 0, 1) * SendRate / 100.f;
            
            double rate2 = MAXMIN(sendScore * 1.0 / sendScoreScope[1], 0, 1) * SendRate / 100.f;
            
            System.err.println(sendScore + "==>" + String.format("%.6f", rate)+","+String.format("%.6f", rate2));
            sendScore -= score;
        }*/
	    
//	    int minCannon = 600;
//	    
//	    int maxCannon = 10000;
//	    
//	    double buffer = 3500D;
//	    
//	    double minUse = minCannon*maxCannon*1.0D/(minCannon+maxCannon);
//	    
//	    double minAfter = buffer*minUse/maxCannon;
//	    
//	    double maxAfter = buffer - minAfter;
//	    
//	    System.out.println("minAfter:"+minAfter+",maxAfter："+maxAfter);
//	    
       
	    
//	    System.out.println(String.format("%.2f", new Double(10)));
	    
	    
	    
	    
	    
//	    List<TblPowerGroup> list = new ArrayList<TblPowerGroup>();
//        list.add(new TblPowerGroup("100001", "cxx1"));
//        list.add(new TblPowerGroup("100002", "cxx2"));
//        list.add(new TblPowerGroup("100003", "cxx6"));
//        list.add(new TblPowerGroup("100003", "cxx5"));
//        list.add(new TblPowerGroup("100004", "cxx5"));
//        list.add(new TblPowerGroup("100004", "cxx6"));
//        Collections.sort(list, new Comparator<TblPowerGroup>() {
//
//            @Override
//            public int compare(TblPowerGroup o1, TblPowerGroup o2) {
//                if (o1.getGroupSn().compareTo(o2.getGroupSn()) == 0) {
//                    return -o1.getNodeName().compareTo(o2.getNodeName());
//                } else {
//                    return -o1.getGroupSn().compareTo(o2.getGroupSn());
//                }
//            }
//
//        });
//        System.out.println(list);   
//	    
	    
	    
	    
	    
	    
//	    
//	    int[][] array = new int[38][2];
//	    array[0][0] = 1;
//	    array[0][1] = 1;
	    
	    
	    
	    
//	    float a=500F;
//	    int b = 9;
//	    
//	    System.out.println(a*b/10000);
	    
	   /* List<Integer> list = new ArrayList<>();
	    for(int i=0;i<11;i++){
	        list.add(i);
	    }
	    
	    for(int i=list.size()-1;i>=0;i--){
	        if(i%2 == 0){
                list.remove(i);
            }
	    }
	    System.out.println(list);
	    
	    for(int i=0;i<list.size();i++){
             list.remove(i);
        }
	    
	    System.out.println(list);*/
	    
//	    Date d = com.johnny.xia.util.date.DateUtil.str2Date("2016-11-07 00:00:00", "yyyy-MM-dd HH:mm:ss");
//	    
//	    Date d2 = new Date();
//	    System.out.println(d2);
//	    
//	    d2.setTime(d.getTime());
//	    System.out.println(d2);
	    
//	    int i = 100;
//	    
//	    System.out.println(i*1.0F/100);
	    
	    
	    
	   /* double life = 2D;
	    int cannon = 100;
	   double t = ((life/10/Math.log10(life*5))*Math.pow(cannon*100,0.18)*1);
	   
	   System.err.println(t);
	   
	   
	   List<Integer> ranks = new ArrayList<>();
	   
	   ranks.add(1);
	   ranks.add(2);
	   ranks.add(3);
	   ranks.add(4);
	   ranks.add(5);
	   
	   System.err.println(ranks.indexOf(0));*/
	    
//	    System.out.println(Math.pow(1000,0.25));
//	    System.out.println(Math.sqrt(Math.sqrt(1000)));
	    
//	    System.out.println(Math.pow(0.7, 1));
//	    System.out.println(Math.pow(0.7, 2));
//	    System.out.println(Math.pow(0.7, 3));
//	    
//	    System.out.println(Math.pow(0.9, 1));
//	    System.out.println(Math.pow(0.9, 2));
//	    System.out.println(Math.pow(0.9, 3));
	    
//	    int a = -10;
//	    int b = 100000;
//	    
//	    for(int a=200000;a>=-200000;){
//	        if(a == 0){
//	            a = a-100;
//	            continue;
//	        }
//	        System.out.println(a+"==>"+(a/b)+"=="+(a/Math.abs(a)));
//	        a = a-10000;
//	    }
	    
	  
	    
	    /*
	    
	    String[] rr = "Y102610231086409-63381451*qbqd*qq".split("\\*");
	    System.out.println(rr.length);
	    
//	    System.err.println(500000 / (Math.sqrt(100)*10) * (1+5*1));
//		for(int i=0;i<10;i++){
//			Mytest test = new Mytest();
//			test.setName("thread-"+i);
//			test.start();
//		}
	    
        for (int i = 0; i < 1000; i++){
            int r = RandUtil.RandInt(100, 99990000);
            String[] array = new String[] { "0", "0", "0", "00" };
            if (r < 10000){
                String t = String.valueOf(r / 100);
                int index = 2;
                for (int n = t.length() - 1; n >= 0; n--){
                    array[index--] = String.valueOf(t.charAt(n));
                }
                String result = "";
                for (String str : array){
                    result += str + "|";
                }
                System.out.println(r+" ===> " + result +"  ==>  "+(r-r%100));
            }else{
               String number = String.valueOf(r);
               String s1 = number.substring(0,3);
               int lastNum = number.substring(3).length();
               for(int n=0;n<s1.length();n++){
                   array[n] = String.valueOf(s1.charAt(n));
               }
               String s = "";
               for(int n=0;n<lastNum;n++){
                   s+="0";
               }
               array[3] = s;
               
               String result = "";
               for (String str : array){
                   result += str + "|";
               }
               
               System.out.println(r+" ===> " + result +"  ==>  "+(s1+s));
            }

           

        }
	    */
		/*
		
//		十进制转成二进制 
		System.out.println(Integer.toBinaryString(10)); 

//		十进制转成八进制 
		System.out.println(Integer.toOctalString(10)); 

//		十进制转成十六进制： 
		System.out.println(Integer.toHexString(10));
		
//		二进制转十进制 
		System.out.println(Integer.valueOf("10100",2).toString());

//		八进制转成十进制 
		System.out.println(Integer.valueOf("125",8).toString());

//		十六进制转成十进制 
		System.out.println(Integer.valueOf("ABCDEF",16).toString());
		
		System.out.println(10<<1);
		
		System.out.println(Integer.toBinaryString(10<<1));
		
		
		String key = "applynum";
		String value = "applynum10001";
		
		System.out.println(value.substring(key.length()));
		
		System.err.println(Math.sqrt(10));*/
		
//	    listPage(1);
	}
	
    public static void listPage( int currentPage){
        
        List<Integer> list = new ArrayList<Integer>();
        for (int i = 1; i < 101; i++){
            list.add(i);
        }

        int pagesize = 20;
        int totalcount = list.size();

        int pagecount = 0;

        int m = totalcount % pagesize;

        if (m > 0){
            pagecount = totalcount / pagesize + 1;
        }else{
            pagecount = totalcount / pagesize;
        }

        if (m == 0){
            List<Integer> subList = list.subList((currentPage - 1) * pagesize, pagesize * (currentPage));
            System.out.println(subList);
        }else{
            if (currentPage == pagecount){
                List<Integer> subList = list.subList((currentPage - 1) * pagesize, totalcount);
                System.out.println(subList);
            }else{
                List<Integer> subList = list.subList((currentPage - 1) * pagesize, pagesize * (currentPage));
                System.out.println(subList);
            }

        }
    }  
	
	public void run(){
//		HttpClientUtil.get(command);
		System.out.println(along.incrementAndGet());
		blong = blong+1;
		System.out.println("--"+blong);
	}
	
}

class TblPowerGroup {
    private String groupSn;
    private String nodeName;

    public TblPowerGroup(String groupSn, String nodeName) {
        super();
        this.groupSn = groupSn;
        this.nodeName = nodeName;
    }

    public String getGroupSn() {
        return groupSn;
    }

    public void setGroupSn(String groupSn) {
        this.groupSn = groupSn;
    }

    public String getNodeName() {
        return nodeName;
    }

    public void setNodeName(String nodeName) {
        this.nodeName = nodeName;
    }

    @Override
    public String toString() {
        return "TblPowerGroup [groupSn=" + groupSn + ", nodeName=" + nodeName
                + "]";
    }

}

class RedRate{
    int num;
    float rate;
    
    public RedRate(){}
    public RedRate(int num,float rate){
        this.num = num;
        this.rate = rate;
    }
    
    @Override
    public String toString(){
        return "num:"+num+",rate:"+rate;
    }

    
    public int getNum(){
        return num;
    }
    
    public float getRate(){
        return rate;
    }
    
    public void setNum(int num){
        this.num = num;
    }
    
    public void setRate(float rate){
        this.rate = rate;
    }
    
    
}
